package test_package;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.HashMap;

public class Test6 {
    public static void main(String[] args) throws NoSuchFieldException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        // JDK9以上版本使用反射，需要加上
        /*
            --add-opens java.base/java.lang=ALL-UNNAMED
            --add-opens java.base/java.util=ALL-UNNAMED
            --add-opens java.base/java.nio=ALL-UNNAMED
            --add-opens java.base/sun.nio.ch=ALL-UNNAMED
         */
        // VM options
        Class<HashMap> clazz = HashMap.class;
        Constructor<HashMap> constructor = clazz.getDeclaredConstructor();
        constructor.setAccessible(true);
        HashMap hashMap = constructor.newInstance();
        hashMap.put("1","1");
        Field table = clazz.getDeclaredField("table");
        table.setAccessible(true);
        Object[] o = (Object[]) table.get(hashMap);
        System.out.println(Arrays.toString(o));

    }
}
